// vuex-persistedstate
import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from 'vuex-persistedstate';

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
      user: null,
      token: ''
    },
    mutations: {
      setUser(state, user) {
        state.user = user;
      },
      setToken(state, token) {
        state.token = token;
      }
    },
    plugins: [createPersistedState({
      key: 'myVuexStore', // 存储的键名
      storage: window.localStorage, // 存储方式，默认是 localStorage
      paths: ['user', 'token'] // 只持久化这两个状态
    })]
});